Skip to contentSkip to conversation

Change in openvpn[master]: win: calculate address string buffer size

Openvpn-devel In review d12fk (Code Review) 2 participants 6 messages Mar 14, 2025 – Mar 24, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1741926089000.I23710b1f5b2122ec1f14465911836c0f0afa9c64@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/908?usp=email

to review the following change.

Change subject: win: calculate address string buffer size
......................................................................

win: calculate address string buffer size

Instead of making the string buffer statically sized for a max. of four addresses, calculate it to hold up to the max number of addresses a dns_cfg_message_t can hold (currently four as well). Improves the code so that it doesn't rely on the addresses never being more than four in the future.

Change-Id I23710b1f5b2122ec1f14465911836c0f0afa9c64

---
M src/openvpnserv/interactive.c

1 file changed, 4 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/908/1

src/openvpnserv/interactive.c +4 -3
index eb3c867..90af02d 100644
@@ -1866,9 +1866,10 @@
     int addr_len = msg->addr_len;
 
     /* sanity check */
-    if (addr_len > _countof(msg->addr))
+    const size_t max_addrs = _countof(msg->addr);
+    if (addr_len > max_addrs)
     {
-        addr_len = _countof(msg->addr);
+        addr_len = max_addrs;
     }
 
     if (!msg->iface.name[0]) /* interface name is required */
@@ -1918,7 +1919,7 @@
     if (msg->addr_len > 0)
     {
         /* prepare the comma separated address list */
-        CHAR addrs[256]; /* large enough to hold four IPv4 / IPv6 address strings */
+        CHAR addrs[max_addrs * 64]; /* 64 is enough for one IPv4/6 address */
         size_t offset = 0;
         for (int i = 0; i < addr_len; ++i)
         {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/908?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64
Gerrit-Change-Number: 908
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/908?usp=email )

Change subject: win: calculate address string buffer size
......................................................................

Patch Set 6: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/908?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64
Gerrit-Change-Number: 908
Gerrit-PatchSet: 6
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Thu, 20 Mar 2025 17:13:57 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH v6 1/1 win: calculate address string buffer size

In reply to a message not in the archive

From: Heiko Hund <[email protected]...>

Instead of making the string buffer statically sized for a max. of four addresses, calculate it to hold up to the max number of addresses a dns_cfg_message_t can hold (currently four as well). Improves the code so that it doesn't rely on the addresses never being more than four in the future.

Change-Id I23710b1f5b2122ec1f14465911836c0f0afa9c64

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/908
This mail reflects revision 6 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

src/openvpnserv/interactive.c +4 -3
index abbc916..100c69a 100644
@@ -1857,9 +1857,10 @@
     int addr_len = msg->addr_len;
 
     /* sanity check */
-    if (addr_len > _countof(msg->addr))
+    const size_t max_addrs = _countof(msg->addr);
+    if (addr_len > max_addrs)
     {
-        addr_len = _countof(msg->addr);
+        addr_len = max_addrs;
     }
 
     if (!msg->iface.name[0]) /* interface name is required */
@@ -1909,7 +1910,7 @@
     if (msg->addr_len > 0)
     {
         /* prepare the comma separated address list */
-        CHAR addrs[256]; /* large enough to hold four IPv4 / IPv6 address strings */
+        CHAR addrs[max_addrs * 64]; /* 64 is enough for one IPv4/6 address */
         size_t offset = 0;
         for (int i = 0; i < addr_len; ++i)
         {
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: win: calculate address string buffer size

Thanks for future-proofing this part of the code - it's fine today, but we might bump the number of allowed DNS addresses to "8" one day, and then the old code was at-risk for overflows...

I haven't actually tested it, just stared at it for a bit, asked mingw ("no warnings") and we have Frank's +2 in gerrit.

Your patch has been applied to the master branch.

commit 8ea5debaea01da5fee56fbad56b50820c1beee92

Author: Heiko Hund
Date:   Mon Mar 24 09:33:44 2025 +0100
     win: calculate address string buffer size

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg31196.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#7) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/908?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: win: calculate address string buffer size
......................................................................

win: calculate address string buffer size

Instead of making the string buffer statically sized for a max. of four addresses, calculate it to hold up to the max number of addresses a dns_cfg_message_t can hold (currently four as well). Improves the code so that it doesn't rely on the addresses never being more than four in the future.

Change-Id I23710b1f5b2122ec1f14465911836c0f0afa9c64

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31196.html

---
M src/openvpnserv/interactive.c

1 file changed, 4 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/908/7

src/openvpnserv/interactive.c +4 -3
index 50363b6..e64ac30 100644
@@ -1848,9 +1848,10 @@
     int addr_len = msg->addr_len;
 
     /* sanity check */
-    if (addr_len > _countof(msg->addr))
+    const size_t max_addrs = _countof(msg->addr);
+    if (addr_len > max_addrs)
     {
-        addr_len = _countof(msg->addr);
+        addr_len = max_addrs;
     }
 
     if (!msg->iface.name[0]) /* interface name is required */
@@ -1900,7 +1901,7 @@
     if (msg->addr_len > 0)
     {
         /* prepare the comma separated address list */
-        CHAR addrs[256]; /* large enough to hold four IPv4 / IPv6 address strings */
+        CHAR addrs[max_addrs * 64]; /* 64 is enough for one IPv4/6 address */
         size_t offset = 0;
         for (int i = 0; i < addr_len; ++i)
         {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/908?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64
Gerrit-Change-Number: 908
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/908?usp=email )

Change subject: win: calculate address string buffer size
......................................................................

win: calculate address string buffer size

Instead of making the string buffer statically sized for a max. of four addresses, calculate it to hold up to the max number of addresses a dns_cfg_message_t can hold (currently four as well). Improves the code so that it doesn't rely on the addresses never being more than four in the future.

Change-Id I23710b1f5b2122ec1f14465911836c0f0afa9c64

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31196.html

---
M src/openvpnserv/interactive.c

1 file changed, 4 insertions(+), 3 deletions(-)
src/openvpnserv/interactive.c +4 -3
index 50363b6..e64ac30 100644
@@ -1848,9 +1848,10 @@
     int addr_len = msg->addr_len;
 
     /* sanity check */
-    if (addr_len > _countof(msg->addr))
+    const size_t max_addrs = _countof(msg->addr);
+    if (addr_len > max_addrs)
     {
-        addr_len = _countof(msg->addr);
+        addr_len = max_addrs;
     }
 
     if (!msg->iface.name[0]) /* interface name is required */
@@ -1900,7 +1901,7 @@
     if (msg->addr_len > 0)
     {
         /* prepare the comma separated address list */
-        CHAR addrs[256]; /* large enough to hold four IPv4 / IPv6 address strings */
+        CHAR addrs[max_addrs * 64]; /* 64 is enough for one IPv4/6 address */
         size_t offset = 0;
         for (int i = 0; i < addr_len; ++i)
         {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/908?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23710b1f5b2122ec1f14465911836c0f0afa9c64
Gerrit-Change-Number: 908
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged